#cs
	Shizuha Version 1.0.0.0
	Senkom Mitra Polri eQSO Scheduler

	@author Julot <andy.julot@gmail.com>
	@since Thursday, May 10, 2012. 10:17 AM


	Example content of Shizuha.ini

	[Connect]
	# Valid entry is [#]=[time]
	# Example:
	#   1=08:00:00
	#   2=09:00:00
	1=14:05:00
	2=14:05:10

	[Disconnect]
	# @see Connect
	1=14:05:20

	[ChangeRoom]
	# Valid entry is [#]=[time] [room name]
	# Example:
	#   1=08:00:00 RoomA
	#   2=09:00:00 RoomB
	1=14:05:30 AutoIt
#ce

#include <GUIConstantsEx.au3>

$eqso = '  Senkom Mitra Polri - Komunikasi via eQSO M0ZPD  V2.1'
$eqso &= "                                   "
$connectId = 1000
$disconnectId = 1038
$roomId = 1001

Func connect()
	ControlClick($eqso, 'Hubungkan', $connectId, 'left')
	Sleep(1000)
EndFunc   ;==>connect

Func disconnect()
	ControlClick($eqso, 'Putuskan', $disconnectId, 'left')
	Sleep(1000)
EndFunc   ;==>disconnect

Func changeRoom($room)
	ControlSetText($eqso, '', $roomId, '')
	ControlSend($eqso, '', $roomId, $room & @CRLF)
	Sleep(1000)
EndFunc   ;==>changeRoom

Func readIni($section)
	$sections = IniReadSection('Shizuha.ini', $section)
	If $sections == 1 Or @error == 1 Then
		Return False
	Else
		Return $sections
	EndIf
EndFunc   ;==>readIni

Func main()
	$connects = readIni('Connect')
	$disconnects = readIni('Disconnect')
	$changeRooms = readIni('ChangeRoom')
	While 1
		$now = @HOUR & ':' & @MIN & ':' & @SEC
		If $connects <> False Then
			For $i = 1 To $connects[0][0]
				If $connects[$i][1] == $now Then
					connect()
				EndIf
			Next
		EndIf

		If $disconnects <> False Then
			For $i = 1 To $disconnects[0][0]
				If $disconnects[$i][1] == $now Then
					disconnect()
				EndIf
			Next
		EndIf

		If $changeRooms <> False Then
			For $i = 1 To $changeRooms[0][0]
				$values = StringSplit($changeRooms[$i][1], ' ')
				If $values[0] == 2 Then
					If $values[1] == $now Then
						changeRoom($values[2])
					EndIf
				EndIf
			Next
		EndIf

		Sleep(100)
	WEnd
EndFunc   ;==>main

If WinExists($eqso) Then
	main()
Else
	MsgBox(48, 'Not exists', 'eQSO is not exists')
EndIf
